package com.xjtu.chapter07.component;

import javax.swing.*;
import java.awt.*;

/**
 * @author yjq
 * @version 1.0
 * @date 2021/8/19 23:06
 */
public class BasicComponentDemo {
    Frame frame = new Frame("测试基本组件");
    TextArea textArea = new TextArea(5, 20);
    Choice colorChooser = new Choice();

    CheckboxGroup checkboxGroup = new CheckboxGroup();
    Checkbox male = new Checkbox("男", checkboxGroup, true);
    Checkbox female = new Checkbox("女", checkboxGroup, true);

    Checkbox isMarried = new Checkbox("是否已婚");

    TextField textField = new TextField(60);
    Button ok = new Button("确认");
    List colorList = new List(6, true);

    public void init() {
        //组装界面

        //组装底部
        Box bBox = Box.createHorizontalBox();
        bBox.add(textField);
        bBox.add(ok);
        frame.add(bBox, BorderLayout.SOUTH);

        //组装选择部分
        colorChooser.add("红色");
        colorChooser.add("黄色");
        colorChooser.add("蓝色");
        Box cBox = Box.createHorizontalBox();
        cBox.add(colorChooser);
        cBox.add(male);
        cBox.add(female);
        cBox.add(isMarried);

        //组装文本域和选择部分
        Box topLeft = Box.createVerticalBox();
        topLeft.add(textArea);
        topLeft.add(cBox);

        //组装顶部左边与列表框
        colorList.add("红色");
        colorList.add("蓝色");
        Box top = Box.createHorizontalBox();
        top.add(topLeft);
        top.add(colorList);

        frame.add(top);

        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        new BasicComponentDemo().init();
    }
}
